<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />


    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">驳 回</multiuse-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 3)">通 过</multiuse-button>
      <!-- <el-button @click="closeDrawer(2)" type="primary">驳 回</el-button> -->
      <!-- <el-button @click="closeDrawer(3)" type="primary">通 过</el-button> -->
    </div>
  </div>
</template>
<script>
import {getDetail,updateAllocateApply} from '@/api/omSale/allocation/HeadquartersAudit/index.js'
import moment from 'moment'
export default {
  data(){
    this.saveData=null;
    return{
      formList:this.createdFrom(),
    }
  },
  props:['rowData'],
  components: {

  },
  created(){
    this.getDetail(this.rowData);
  },
  methods:{
    createdFrom(){
      return [

        {
          type: 'INPUT',
          label: '调拨单号',
          fieldName: 'applyNo',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '调出方',
          fieldName: 'fromDealerName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '调入方',
          fieldName: 'toDealerName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '调拨人',
          fieldName: 'applyPersonName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '调拨申请日期',
          fieldName: 'applyDate',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'DATE',
          label: '审批通过日期',
          fieldName: 'checkDate',
          placeholder: '请输入',
          disabled:true,
          dateType:'exactdate'
        },

        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'applyRemark',
          selfCols:3,
          disabled:true,
        },
        {
          type: 'TEXT_AREA',
          label: '审核意见',
          fieldName: 'checkDesc',
          selfCols:3,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
      ]
    },
    async getDetail(data){
      let res=await getDetail({id:data.id})
      for (let i in res.data) {
      this.formList.map(x => {
          if (i == x.fieldName) {
            x.initialValue = res.data[i];
          }
        });
      }
    },
    changeHandle(val){
      this.saveData=val;
    },

    async closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }else if(type==2){
          this.$refs.from.SUBMIT_FORM();
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          json.id=this.rowData.id;
          json.applyStatus=60121004;
          let res = await updateAllocateApply(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '驳回成功',
              type: 'success'
            });
            this.$emit('close', json);
          }else{
            this.saveData=null;
          }
        }
      }else{
        let str=this.formList.find(x=>x.fieldName=='checkDesc').initialValue;
          let json =str?{checkDesc:str}:{}
          json.id=this.rowData.id;
          json.applyStatus=60121003;
          let res = await updateAllocateApply(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '通过成功',
              type: 'success'
            });
            this.$emit('close', json);
          }
      }
    }

  }
}
</script>
